package com.ruoyi.TraditionalCultureSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.TraditionalCultureSys.domain.TraditionalBuildings;
import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.TraditionalCultureSys.domain.RedRelics;
import com.ruoyi.TraditionalCultureSys.service.IRedRelicsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 红色经典Controller
 * 
 * @author ruoyi
 * @date 2024-06-24
 */
@RestController
@RequestMapping("/TraditionalCultureSys/relics")
public class RedRelicsController extends BaseController
{
    @Autowired
    private IRedRelicsService redRelicsService;

    /**
     * 查询红色经典列表
     */
    @PreAuthorize("@ss.hasPermi('list')")
    @GetMapping("/list")
    public TableDataInfo list(RedRelics redRelics)
    {
        startPage();
        List<RedRelics> list = redRelicsService.selectRedRelicsList(redRelics);
        return getDataTable(list);
    }

    /**
     * 导出红色经典列表
     */
    @PreAuthorize("@ss.hasPermi('export')")
    @Log(title = "红色经典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RedRelics redRelics)
    {
        List<RedRelics> list = redRelicsService.selectRedRelicsList(redRelics);
        ExcelUtil<RedRelics> util = new ExcelUtil<RedRelics>(RedRelics.class);
        util.exportExcel(response, list, "红色经典数据");
    }

    /**
     * 获取红色经典详细信息
     */
    @PreAuthorize("@ss.hasPermi('query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(redRelicsService.selectRedRelicsById(id));
    }

    /**
     * 新增红色经典
     */
    @PreAuthorize("@ss.hasPermi('add')")
    @Log(title = "红色经典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RedRelics redRelics)
    {
        return toAjax(redRelicsService.insertRedRelics(redRelics));
    }

    /**
     * 修改红色经典
     */
    @PreAuthorize("@ss.hasPermi('edit')")
    @Log(title = "红色经典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RedRelics redRelics)
    {
        return toAjax(redRelicsService.updateRedRelics(redRelics));
    }

    /**
     * 删除红色经典
     */
    @PreAuthorize("@ss.hasPermi('remove')")
    @Log(title = "红色经典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(redRelicsService.deleteRedRelicsByIds(ids));
    }

    /**
     *
     * @return 全部红色经典信息
     */
    @Anonymous
    @ResponseBody
    @RequestMapping(value = "/getAllRedRelics", produces = {"application/json;charset=utf-8"})
    public AjaxResult getAllRedRelics() {
        List<RedRelics> redRelics = redRelicsService.getAllRedRelics();
        return AjaxResult.success("redRelics",redRelics);
    }



}
